/**
 * Created By wifi_uncle on 2019/12/30
 */
import Vue from 'vue'
import API from '../api'
import Utils from '../utils'
import Config from '../config'

export default {
  /**
   * 获取楼盘列表
   */
  getPremiseList ({params, _this}) {
    let url = Utils.getPrefix() + API.PREMISE.GET_PREMISE_LIST_FOR_PARTNER
    const errorMsg = '获取楼盘列表失败'
    const body = {};
    body.params = {
      userId: window.localStorage.getItem("userId")
    };
    return _this.$http.post(url, body).then(rsp => {
      const data = rsp.body
      //if (data && data.result === Config.SUCCESS_CODE) {
        return Promise.resolve(data.resData)
      // } else {
      //   Utils.showFailMsg(errorMsg)
      //   return Promise.reject(data)
      // }
    }, e => {
      Utils.showFailMsg(errorMsg)
      return Promise.reject(e)
    })
  },
  /**
   * 通过楼盘状态获取满足状态的楼盘列表
   * @param params
   * @param _this
   * @returns {PromiseLike<any> | Promise<any> | * | Promise$1 | PromiseObj}
   */
  getPremisesListByStatus ({params, _this}) {
    let url = Utils.getPrefix() + API.PREMISE.GET_PREMISE_LIST_BY_STATUS
    const errorMsg = '获取楼盘列表失败'
    const body = {};
    body.params = {
      userId: window.localStorage.getItem("userId"),
      premisesStatus: params.premisesStatus
    };

    return _this.$http.post(url, body).then(rsp => {
      const data = rsp.body
      return Promise.resolve(data.resData)
    }, e => {
      Utils.showFailMsg(errorMsg)
      return Promise.reject(e)
    })
  },
  getPartnerByPremisesList (premisesId, _this) {
    let url = Utils.getPrefix(_this) + API.PREMISE.GET_PARTNER_BY_PREMISES
    let body = {}
    body.params = {
      premisesId: premisesId
    }
    return _this.$http.post(url, body).then(rsp => { // 无同步
      const data = rsp.body
      if (data && data.result === Config.SUCCESS_CODE) {
        return Promise.resolve(data.resData.partnerList)
      } else {
        Utils.showFailMsg('获取楼盘驻守失败')
        return Promise.reject(data)
      }
    }, e => {
      Utils.showFailMsg('获取楼盘驻守失败')
      return Promise.reject(e)
    })
  },

}
